﻿//-----------------------------------------------------------------------
// <copyright file="BuildReleaseNotes.cs">(c). All other rights reserved.</copyright>
//-----------------------------------------------------------------------
namespace TfsBuildExtensions.Activities.TeamFoundationServer
{
    using System.Collections.Generic;

    /// <summary>
    /// Extension methods for SortedDictionary
    /// </summary>
    public static class SortedDictionaryExtension
    {
        /// <summary>
        /// Try adding the key and value to the collection
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="sortedDictionary"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static bool TryAdd<TKey, TValue>(this SortedDictionary<TKey, TValue> sortedDictionary, TKey key, TValue value)
        {
            if (!sortedDictionary.ContainsKey(key))
            {
                sortedDictionary.Add(key, value);
                return true;
            }
            return false;
        }
    }
}
